#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e5 + 10;
int n, m;
string s;

int sum[MAXN][10];

void init() {
    string b = "abc";
    for (int i = 1; i <= 6; i++) {
        for (int j = 0; j < n; j++) {
            char target = b[j % 3];
            bool diff = s[j] != target;
            sum[j + 1][i] = sum[j][i] + (diff ? 1 : 0);
        }

        next_permutation(b.begin(), b.end());
    }
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m >> s;
    init();
    int l, r;

    while (m--) {
        cin >> l >> r;

        int res = INT_MAX;
        for (int i = 1; i <= 6; i++) {
            res = min(res, sum[r][i] - sum[l - 1][i]);
        }
        cout << res << endl;
    }
    return 0;
}